package com.taimi.newdemo.controller;

import com.taimi.newdemo.dto.UserDto;
import com.taimi.newdemo.dto.mapper.UserMapper;
import com.taimi.newdemo.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private UserService userService;

    @PostMapping(value = "/login")
    public ResponseEntity<String> authLogin(String username, String password) {
        return ResponseEntity.ok().body("success");
    }

    @PostMapping(value = "/login2")
    public ResponseEntity<String> authLogin2(@RequestBody UserDto userDto) {
        boolean authLogin = userService.authLogin(UserMapper.INSTANCE.userToUserEntity(userDto));
        String data;
        if (authLogin) {
            data = "success";
        } else {
            data = "用户名或密码错误";
        }
        return ResponseEntity.ok().body(data);
    }

}
